import router from './router'
import store from './store'

// 白名单,不需要token的页面
const whiteList = ['/login', '/', '/search']
router.beforeEach((to, from, next) => {
  const { token } = store.state.user
  if (token) {
    next()
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next(`/login?redirect=${to.path}`)
    }
  }
})
